/*
	@file: log/include/Singleton.h
	@author: Wolfhead
 */
#ifndef _LOG_SINGLETON_H_
#define _LOG_SINGLETON_H_

#include <boost/thread.hpp>

namespace logger
{

template<typename T>
class Singleton
{
public:
	static T& instance()
	{
		if (!m_init)
		{
			{
				boost::lock_guard<boost::mutex> lock_guard(m_mutex);
				if (!m_init)
				{
					m_instance = boost::shared_ptr<T>(new T);
					m_init = true;
				}
			}
		}

		assert(m_init);
		return *m_instance;
	}

private:

	static bool m_init;

	static boost::mutex m_mutex;

	static boost::shared_ptr<T> m_instance;
};


template<typename T>
bool Singleton<T>::m_init = false;

template<typename T>
boost::mutex Singleton<T>::m_mutex;

template<typename T>
boost::shared_ptr<T> Singleton<T>::m_instance;

}//namespace logger

#endif
